package com.leyou.search.web;

import com.leyou.search.dto.SearchDTO;
import com.leyou.search.pojo.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/suggestion")
    public Mono<List<String>> getSugg(@RequestParam("key")String key){

        return this.searchService.getSugg(key);
    }

    /**
     * 商品的分页查询
     * @param searchDTO
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> listData(
            @RequestBody SearchDTO searchDTO){

        return this.searchService.listData(searchDTO);
    }

    /**
     * 商品的过滤条件查询
     * @param searchDTO
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<?>>> listFilter(
            @RequestBody SearchDTO searchDTO){

        return this.searchService.listFilter(searchDTO);
    }
}
